package test.netease.version2.chapter1.lesson1_1_3;

/**
 * @author zhangrui
 * @date 2020-04-24 19:16
 * @since 1.0
 */
public class Demo {
    public static void main(String[] args) throws Exception{

        StopThread stop = new StopThread();

        Thread thread = new Thread(stop);
        thread.start();

        Thread.sleep(1000);

        //使用stop，线程被强制停止，run方法被中途切断
        //thread.stop();

        //使用interrupt，线程虽然被停止，但它还是完成了run方法
        thread.interrupt();

        while (thread.isAlive()){
            //确保线程已经停止
        }

        stop.print();
    }
}
